import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-09-15
 * Time: 11:41
 */
public class JDBCDemo2{
        public static void main(String[] args) throws SQLException {
                Scanner scanner=new Scanner(System.in);
                System.out.println("请输入你要删除的id号");
                int id=scanner.nextInt();

                DataSource dataSource=new MysqlDataSource();
                ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/d09073?characterEncoding=utf8&useSSL=false");
                ((MysqlDataSource)dataSource).setUser("root");
                ((MysqlDataSource)dataSource).setPassword("1111");

                Connection connection=dataSource.getConnection();

                String sql="delete from student where id=?";
                PreparedStatement statement=connection.prepareStatement(sql);
                statement.setInt(1,id);

                int n=statement.executeUpdate();
                System.out.println("n="+n);

                statement.close();
                connection.close();
        }
}
